package apigateway.project.core.filter.router;

import apigateway.project.commen.config.Rule;
import apigateway.project.core.redis.RedisUtils;

public class RedisCircuitBreaker {
    private RedisUtils redisUtils;

    public RedisCircuitBreaker(RedisUtils redisUtils) {
        this.redisUtils = redisUtils;
    }

    public boolean doCircuitBreak(String key, Rule.RedisCircuitBreakerConfig  circuitBreakerConfig, long responseTime) {

        boolean result = redisUtils.isCircuitBreakerOpen(key, circuitBreakerConfig.getMinRequestAmount(),
                circuitBreakerConfig.getStatIntervalMs(), circuitBreakerConfig.getSlowRatioThreshold(),
                circuitBreakerConfig.getTimeWindow(), circuitBreakerConfig.getCount(), responseTime);

        return result;

    }



}